# The Flutter tooling requires that developers have CMake 3.10 or later
# installed. You should not increase this version, as doing so will cause
# the plugin to fail to compile for some customers of the plugin.
cmake_minimum_required(VERSION 3.10)
project(tencent_rtc_ffi_library VERSION 0.0.1)

add_library(tencent_rtc_ffi SHARED
        jsoncpp/jsoncpp.cc
        dart_api/dart_api_dl.c
        trtc_plugin_adapter.cc
)

target_include_directories(tencent_rtc_ffi PUBLIC
        trtc_c_api
        dart_api
        dart_api/internal
        jsoncpp
)

set_target_properties(tencent_rtc_ffi PROPERTIES
        PUBLIC_HEADER trtc_plugin_adapter.h
        OUTPUT_NAME "tencent_rtc_ffi"
)

target_compile_definitions(tencent_rtc_ffi PUBLIC DART_SHARED_LIB)

add_library(libliteavsdk SHARED IMPORTED)
if(ANDROID)
    # Support Android 15 16k page size.
    # Check CMake version
    if(CMAKE_VERSION VERSION_LESS "3.13")
        # If the CMake version is lower than 3.13, use set_target_properties
        set_target_properties(tencent_rtc_ffi PROPERTIES LINK_FLAGS "-Wl,-z,max-page-size=16384")
    else()
        # If CMake version is greater than or equal to 3.13, use target_link_options
        target_link_options(tencent_rtc_ffi PRIVATE "-Wl,-z,max-page-size=16384")
    endif()
    target_sources(tencent_rtc_ffi PUBLIC platform_adapter/java/tencent_rtc_jni.cc)
    set(LITEAVSDK_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../android/liteav/jni/${ANDROID_ABI}/libliteavsdk.so)
elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
    set(LITEAVSDK_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../ohos/liteav/libliteavsdk.so)
endif()

set_target_properties(libliteavsdk PROPERTIES IMPORTED_LOCATION ${LITEAVSDK_LIB_PATH})

target_link_libraries(tencent_rtc_ffi libliteavsdk)